using System.Windows.Forms;
using WaterQualityReportSystem.models;

namespace WaterQualityReportSystem
{
    public partial class ReportConfirmDialog : Form
    {
        public ItemData itemData = null;
        public Double Score { get; set; }


        public ReportConfirmDialog(ItemData itemData)
        {
            this.itemData = itemData;
            InitializeComponent();

            showData();
        }

        private void btAbandon_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void btReportToServer_Click(object sender, EventArgs e)
        {
            if (dgvReportData.Rows.Count == 0) {
                MessageBox.Show(this, "没有任何可上报的数据");
                Score = 0;
                return;
            }

            Score = Double.Parse(dgvReportData.Rows[0].Cells["Concentration"].Value.ToString());
            this.DialogResult = DialogResult.OK;
        }

        private void showData()
        {
            // 创建 DataGridView 列
            DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
            column1.HeaderText = "序号";
            column1.Name = "no";

            DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
            column2.HeaderText = "测试项目";
            column2.Name = "TestItem";

            DataGridViewTextBoxColumn column3 = new DataGridViewTextBoxColumn();
            column3.HeaderText = "单位";
            column3.Name = "Unit";

            DataGridViewTextBoxColumn column4 = new DataGridViewTextBoxColumn();
            column4.HeaderText = "浓度";
            column4.Name = "Concentration";

            DataGridViewTextBoxColumn column5 = new DataGridViewTextBoxColumn();
            column5.HeaderText = "吸光";
            column5.Name = "LightAbsorption";

            DataGridViewTextBoxColumn column6 = new DataGridViewTextBoxColumn();
            column6.HeaderText = "透光";
            column6.Name = "LightTransmittance";

            DataGridViewTextBoxColumn column7 = new DataGridViewTextBoxColumn();
            column7.HeaderText = "测试日期";
            column7.Name = "TestDate";

            DataGridViewTextBoxColumn column8 = new DataGridViewTextBoxColumn();
            column8.HeaderText = "测试时间";
            column8.Name = "TestTime";

            // 将列添加到 DataGridView
            dgvReportData.Columns.AddRange(new DataGridViewColumn[] { column1, column2, column3, column4, column5, column6, column7, column8 });

            // 模拟添加数据行
            DataGridViewRow row1 = new DataGridViewRow();
            row1.Cells.AddRange(new DataGridViewCell[] { new DataGridViewTextBoxCell() { Value = itemData.NO }, 
                new DataGridViewTextBoxCell() { Value = itemData.Name }, new DataGridViewTextBoxCell() { Value = itemData.Unit }, 
                new DataGridViewTextBoxCell() { Value = itemData.Concentration }, new DataGridViewTextBoxCell() { Value = itemData.Absorbancy}, 
                new DataGridViewTextBoxCell() { Value = itemData.Transparency }, new DataGridViewTextBoxCell() { Value = itemData.TestDate.ToString("yy-MM-dd") },
                new DataGridViewTextBoxCell() { Value = itemData.TestDate.ToString("HH:mm:ss") } });

            // 将数据行添加到 DataGridView
            dgvReportData.Rows.AddRange(new DataGridViewRow[] { row1});
        }
    }
}
